import sys

import pandas as pd
from sklearn.metrics import f1_score

if __name__ == '__main__':
    df_pred = pd.read_csv(f'log/{sys.argv[1]}/result.csv', header=None, names=['uuid', 'time_in', 'time_out', 'pred'])
    df_truth = pd.read_csv('data/truth.csv', header=None, names=['uuid', 'label'])
    time_diff = (df_pred['time_out'] - df_pred['time_in'])
    time_mask = time_diff <= 500
    f1 = f1_score(df_truth['label'][time_mask], df_pred['pred'][time_mask])
    ratio = time_mask.mean()
    with open(f'log/{sys.argv[1]}/evaluate.txt', 'w') as f:
        f.write(f'avg time: {time_diff.mean()}\n')
        f.write(f'f1 score: {f1}\n')
        f.write(f'ratio   : {ratio}\n')
        f.write(f'score   : {f1 * ratio}\n')
